﻿@model Xms.Web.Models.EditPrivilegeModel

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <a data-toggle="collapse"
                           href="#collapseOne">
                            <strong>@app.T["menu"]</strong>
                        </a>
                    </h3>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="xms-tree-toolbar panel-body">
                        <div class="xms-tree-toolbtn btn btn-xs btn-default"><span class="glyphicon glyphicon-minus"></span> @app.T["expandall"]</div>
                        <div class="xms-tree-toolbtn btn btn-xs btn-default"><span class="glyphicon glyphicon-plus"></span> @app.T["shrinkall"]</div>
                    </div>
                    <div class="panel-body" style="max-height:450px;overflow-y:scroll;">
                        <div id="tree1" data-url="@("/"+app.OrganizationUniqueName)/Privilege/index"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-8">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <a data-toggle="collapse"
                           href="#collapseTwo">
                            <strong>@app.T["edit"]</strong>
                        </a>
                    </h3>
                </div>
                <div id="collapseTwo" class="panel-collapse collapse in">
                    <div class="panel-body" style="max-height:450px;overflow-y:scroll;">
                        <form action="/@app.OrganizationUniqueName/privilege/EditPrivilege" method="post" id="editform" class="form-horizontal" role="form">
                            @Html.AntiForgeryToken()
                            @Html.HiddenFor(x => x.PrivilegeId)
                            <div class="form-group col-sm-12">
                                <label class="col-sm-2 control-label" for="actionstatus">@app.T["operation"]</label>
                                <div class="col-sm-10">
                                    <label class="radio-inline">
                                        <input class="required" name="actionstatus" type="radio" value="0"> @app.T["privilege_editthisnode"]
                                    </label>
                                    <label class="radio-inline">
                                        <input class="required" name="actionstatus" type="radio" value="1" checked> @app.T["privilege_createchildnode"]
                                    </label>
                                    <label class="radio-inline">
                                        <input class="required" name="actionstatus" type="radio" value="2"> @app.T["privilege_createnode"]
                                    </label>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.ParentPrivilegeName, app.T["privilege_parentnode"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.ParentPrivilegeName, new { @id = "ParentPrivilegeName", @disabled = "disabled", @class = "form-control disabled" })
                                    @Html.HiddenFor(x => x.ParentPrivilegeId, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.DisplayName, app.T["privilege_displayname"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.DisplayName, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.SystemName, app.T["privilege_systemname"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.SystemName, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.ClassName, app.T["privilege_classname"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    <div class="input-group">
                                        @Html.TextBoxFor(x => x.ClassName, new { @class = "form-control input-sm" })
                                        <span class="input-group-btn">
                                            <button class="btn btn-default btn-sm" type="button" onclick="Xms.Web.OpenDialog('/tool/selectactionsdialog?singlemode=true','bindSelectedAction')">
                                                <span class="glyphicon glyphicon-search"></span>
                                            </button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.MethodName, app.T["privilege_methodname"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.MethodName, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12 hide">
                                @Html.LabelFor(x => x.BigIcon, app.T["privilege_bigicon"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.BigIcon, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.SmallIcon, app.T["privilege_smallicon"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.SmallIcon, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.Url, app.T["privilege_url"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.Url, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.OpenTarget, app.T["privilege_opentarget"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.OpenTarget, new { @class = "form-control", @value = "iframe" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.AuthorizationEnabled, app.T["privilege_state"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    <label class="radio-inline">
                                        @Html.RadioButtonFor(x => x.AuthorizationEnabled, true, new { @checked = true }) @app.T["enabled"]
                                    </label>
                                    <label class="radio-inline">
                                        @Html.RadioButtonFor(x => x.AuthorizationEnabled, false) @app.T["disabled"]
                                    </label>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.IsVisibled, app.T["privilege_visibled"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    <label class="radio-inline">
                                        @Html.RadioButtonFor(x => x.IsVisibled, true, new { @checked = true }) @app.T["show"]
                                    </label>
                                    <label class="radio-inline">
                                        @Html.RadioButtonFor(x => x.IsVisibled, false) @app.T["hide"]
                                    </label>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.DisplayOrder, app.T["privilege_displayorder"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextBoxFor(x => x.DisplayOrder, new { @class = "form-control" })
                                    <span class="help-block">
                                        @app.T["privilege_displayorder_helptext"]
                                    </span>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                @Html.LabelFor(x => x.Description, app.T["description"], new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.TextAreaFor(x => x.Description, new { @class = "form-control", @rows = "3" })
                                </div>
                            </div>
                            <div class="form-group col-sm-12 text-center" id="form-buttons">
                                <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-saved"></span> @app.T["save"]</button>
                                <button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> @app.T["reset"]</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@section Header {
    <link href="/content/css/jqtree.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <style>
        .xms-mutilauto-input {
            border: 1px solid #ccc;
        }
    </style>
}
@section Scripts {
    <script src="/content/js/xms.utility.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/tree.jquery.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.cookie.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-validate/jquery.validate.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-validate/localization/messages_zh.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script>
        var bsicons = ['glyphicon glyphicon-asterisk',
                    'glyphicon glyphicon-plus',
                    'glyphicon glyphicon-minus',
                    'glyphicon glyphicon-euro',
                    'glyphicon glyphicon-cloud',
                    'glyphicon glyphicon-envelope',
                    'glyphicon glyphicon-pencil',
                    'glyphicon glyphicon-glass',
                    'glyphicon glyphicon-music',
                    'glyphicon glyphicon-search',
                    'glyphicon glyphicon-heart',
                    'glyphicon glyphicon-star',
                    'glyphicon glyphicon-star-empty',
                    'glyphicon glyphicon-user',
                    'glyphicon glyphicon-film',
                    'glyphicon glyphicon-th-large',
                    'glyphicon glyphicon-th',
                    'glyphicon glyphicon-th-list',
                    'glyphicon glyphicon-ok',
                    'glyphicon glyphicon-remove',
                    'glyphicon glyphicon-zoom-in',
                    'glyphicon glyphicon-zoom-out',
                    'glyphicon glyphicon-off',
                    'glyphicon glyphicon-signal',
                    'glyphicon glyphicon-cog',
                    'glyphicon glyphicon-trash',
                    'glyphicon glyphicon-home',
                    'glyphicon glyphicon-file',
                    'glyphicon glyphicon-time',
                    'glyphicon glyphicon-road',
                    'glyphicon glyphicon-download-alt',
                    'glyphicon glyphicon-download',
                    'glyphicon glyphicon-upload',
                    'glyphicon glyphicon-inbox',
                    'glyphicon glyphicon-play-circle',
                    'glyphicon glyphicon-repeat',
                    'glyphicon glyphicon-refresh',
                    'glyphicon glyphicon-list-alt',
                    'glyphicon glyphicon-lock',
                    'glyphicon glyphicon-flag',
                    'glyphicon glyphicon-headphones',
                    'glyphicon glyphicon-volume-off',
                    'glyphicon glyphicon-volume-down',
                    'glyphicon glyphicon-volume-up',
                    'glyphicon glyphicon-qrcode',
                    'glyphicon glyphicon-barcode',
                    'glyphicon glyphicon-tag',
                    'glyphicon glyphicon-tags',
                    'glyphicon glyphicon-book',
                    'glyphicon glyphicon-bookmark',
                    'glyphicon glyphicon-print',
                    'glyphicon glyphicon-camera',
                    'glyphicon glyphicon-font',
                    'glyphicon glyphicon-bold',
                    'glyphicon glyphicon-italic',
                    'glyphicon glyphicon-text-height',
                    'glyphicon glyphicon-text-width',
                    'glyphicon glyphicon-align-left',
                    'glyphicon glyphicon-align-center',
                    'glyphicon glyphicon-align-right',
                    'glyphicon glyphicon-align-justify',
                    'glyphicon glyphicon-list',
                    'glyphicon glyphicon-indent-left',
                    'glyphicon glyphicon-indent-right',
                    'glyphicon glyphicon-facetime-video',
                    'glyphicon glyphicon-picture',
                    'glyphicon glyphicon-map-marker',
                    'glyphicon glyphicon-adjust',
                    'glyphicon glyphicon-tint',
                    'glyphicon glyphicon-edit',
                    'glyphicon glyphicon-share',
                    'glyphicon glyphicon-check',
                    'glyphicon glyphicon-move',
                    'glyphicon glyphicon-step-backward',
                    'glyphicon glyphicon-fast-backward',
                    'glyphicon glyphicon-backward',
                    'glyphicon glyphicon-play',
                    'glyphicon glyphicon-pause',
                    'glyphicon glyphicon-stop',
                    'glyphicon glyphicon-forward',
                    'glyphicon glyphicon-fast-forward',
                    'glyphicon glyphicon-step-forward',
                    'glyphicon glyphicon-eject',
                    'glyphicon glyphicon-chevron-left',
                    'glyphicon glyphicon-chevron-right',
                    'glyphicon glyphicon-plus-sign',
                    'glyphicon glyphicon-minus-sign',
                    'glyphicon glyphicon-remove-sign',
                    'glyphicon glyphicon-ok-sign',
                    'glyphicon glyphicon-question-sign',
                    'glyphicon glyphicon-info-sign',
                    'glyphicon glyphicon-screenshot',
                    'glyphicon glyphicon-remove-circle',
                    'glyphicon glyphicon-ok-circle',
                    'glyphicon glyphicon-ban-circle',
                    'glyphicon glyphicon-arrow-left',
                    'glyphicon glyphicon-arrow-right',
                    'glyphicon glyphicon-arrow-up',
                    'glyphicon glyphicon-arrow-down',
                    'glyphicon glyphicon-share-alt',
                    'glyphicon glyphicon-resize-full',
                    'glyphicon glyphicon-resize-small',
                    'glyphicon glyphicon-exclamation-sign',
                    'glyphicon glyphicon-gift',
                    'glyphicon glyphicon-leaf',
                    'glyphicon glyphicon-fire',
                    'glyphicon glyphicon-eye-open',
                    'glyphicon glyphicon-eye-close',
                    'glyphicon glyphicon-warning-sign',
                    'glyphicon glyphicon-plane',
                    'glyphicon glyphicon-calendar',
                    'glyphicon glyphicon-random',
                    'glyphicon glyphicon-comment',
                    'glyphicon glyphicon-magnet',
                    'glyphicon glyphicon-chevron-up',
                    'glyphicon glyphicon-chevron-down',
                    'glyphicon glyphicon-retweet',
                    'glyphicon glyphicon-shopping-cart',
                    'glyphicon glyphicon-folder-close',
                    'glyphicon glyphicon-folder-open',
                    'glyphicon glyphicon-resize-vertical',
                    'glyphicon glyphicon-resize-horizontal',
                    'glyphicon glyphicon-hdd',
                    'glyphicon glyphicon-bullhorn',
                    'glyphicon glyphicon-bell',
                    'glyphicon glyphicon-certificate',
                    'glyphicon glyphicon-thumbs-up',
                    'glyphicon glyphicon-thumbs-down',
                    'glyphicon glyphicon-hand-right',
                    'glyphicon glyphicon-hand-left',
                    'glyphicon glyphicon-hand-up',
                    'glyphicon glyphicon-hand-down',
                    'glyphicon glyphicon-circle-arrow-right',
                    'glyphicon glyphicon-circle-arrow-left',
                    'glyphicon glyphicon-circle-arrow-up',
                    'glyphicon glyphicon-circle-arrow-down',
                    'glyphicon glyphicon-globe',
                    'glyphicon glyphicon-wrench',
                    'glyphicon glyphicon-tasks',
                    'glyphicon glyphicon-filter',
                    'glyphicon glyphicon-briefcase',
                    'glyphicon glyphicon-fullscreen',
                    'glyphicon glyphicon-dashboard',
                    'glyphicon glyphicon-paperclip',
                    'glyphicon glyphicon-heart-empty',
                    'glyphicon glyphicon-link',
                    'glyphicon glyphicon-phone',
                    'glyphicon glyphicon-pushpin',
                    'glyphicon glyphicon-usd',
                    'glyphicon glyphicon-gbp',
                    'glyphicon glyphicon-sort',
                    'glyphicon glyphicon-sort-by-alphabet',
                    'glyphicon glyphicon-sort-by-alphabet-alt',
                    'glyphicon glyphicon-sort-by-order',
                    'glyphicon glyphicon-sort-by-order-alt',
                    'glyphicon glyphicon-sort-by-attributes',
                    'glyphicon glyphicon-sort-by-attributes-alt',
                    'glyphicon glyphicon-unchecked',
                    'glyphicon glyphicon-expand',
                    'glyphicon glyphicon-collapse-down',
                    'glyphicon glyphicon-collapse-up',
                    'glyphicon glyphicon-log-in',
                    'glyphicon glyphicon-flash',
                    'glyphicon glyphicon-log-out',
                    'glyphicon glyphicon-new-window',
                    'glyphicon glyphicon-record',
                    'glyphicon glyphicon-save',
                    'glyphicon glyphicon-open',
                    'glyphicon glyphicon-saved',
                    'glyphicon glyphicon-import',
                    'glyphicon glyphicon-export',
                    'glyphicon glyphicon-send',
                    'glyphicon glyphicon-floppy-disk',
                    'glyphicon glyphicon-floppy-saved',
                    'glyphicon glyphicon-floppy-remove',
                    'glyphicon glyphicon-floppy-save',
                    'glyphicon glyphicon-floppy-open',
                    'glyphicon glyphicon-credit-card',
                    'glyphicon glyphicon-transfer',
                    'glyphicon glyphicon-cutlery',
                    'glyphicon glyphicon-header',
                    'glyphicon glyphicon-compressed',
                    'glyphicon glyphicon-earphone',
                    'glyphicon glyphicon-phone-alt',
                    'glyphicon glyphicon-tower',
                    'glyphicon glyphicon-stats',
                    'glyphicon glyphicon-sd-video',
                    'glyphicon glyphicon-hd-video',
                    'glyphicon glyphicon-subtitles',
                    'glyphicon glyphicon-sound-stereo',
                    'glyphicon glyphicon-sound-dolby',
                    'glyphicon glyphicon-sound-5-1',
                    'glyphicon glyphicon-sound-6-1',
                    'glyphicon glyphicon-sound-7-1',
                    'glyphicon glyphicon-copyright-mark',
                    'glyphicon glyphicon-registration-mark',
                    'glyphicon glyphicon-cloud-download',
                    'glyphicon glyphicon-cloud-upload',
                    'glyphicon glyphicon-tree-conifer',
                    'glyphicon glyphicon-tree-deciduous'];

        var btnColorArr = ['btn-default', 'btn-primary', 'btn-success', 'btn-info', 'btn-warning', 'btn-danger', 'btn-link'];
        var btnSizeArr = ['btn-lg', '', 'btn-sm', 'btn-xs'];
        var $tree = $('#tree1'), $form = $('#editform');
        var $editaction = $form.find("input[name='actionstatus'][value='0']");
        var $childaction = $form.find("input[name='actionstatus'][value='1']");
        var $siblingaction = $form.find("input[name='actionstatus'][value='2']");
        $(function () {
            initTree();
            //表单验证
            Xms.Web.Form($form, function (response) {
                Xms.Web.Toast(response.Content, response.IsSuccess);
                if (response.IsSuccess) {
                    loadTree();
                    $form.resetForm();
                    $childaction.trigger("click");
                }
            });

            //操作类型
            $form.find("input[name='actionstatus']").click(function () {
                var id = $form.find("input[name='privilegeid']").val();
                var node = $tree.tree('getSelectedNode');
                if (id == '' || id == Xms.Utility.Guid.EmptyGuid.ToString()) {
                    if (node != false) {
                        id = node.id;
                    }
                }
                $form.find("input[name='actionstatus']").prop("checked", false);
                if ($(this).val() == 0)//编辑本节点
                {
                    doEditAction(id);
                }
                else if ($(this).val() == 1)//新增子节点
                {
                    doChildAction(id);
                }
                else if ($(this).val() == 2)//新增同级节点
                {
                    doCreateAction(id, node);
                }
            });

            $('#BigIcon').xmsAutoComplete({
                datas: bsicons,
                itemClass: 'iconsarr',
                itemTmpl: '<li class="{{itemClass}} {{itemOther}}" value="{{itemValue}}">{{itemTitle}}</li>',
                dataFilter: function (data) {
                    var res = [];
                    $.each(data, function (i, n) {
                        var obj = {
                            value: n,
                            other: n,
                        }
                        res.push(obj);
                    });
                    return res;
                }
                , overflowPar: $('#BigIcon').parents('.panel-body:first')
                ,offsetL:13
            });

            $('#SmallIcon').xmsAutoComplete({
                datas: bsicons,
                itemClass: 'iconsarr',
                itemTmpl: '<li class="{{itemClass}} {{itemOther}}" value="{{itemValue}}">{{itemTitle}}</li>',
                dataFilter: function (data) {
                    var res = [];
                    $.each(data, function (i, n) {
                        var obj = {
                            value: n,
                            other: n,
                        }
                        res.push(obj);
                    });
                    return res;
                }
                , overflowPar: $('#BigIcon').parents('.panel-body:first')
                , offsetL: 13
            });

            var entitySelect = $('#Url');
           // entitySelect.empty();
            entitySelect.mutilAutoComplete({
                getType: 'ajax',
                ajax: {
                    url: "/api/schema/entity",
                    data: { getall: true },
                },
                replaceList: [{ key: 'itemClass', value: 'itemClass' }, { key: 'itemValue', value: 'entityid' }, { key: 'entityname', value: 'name' }, { key: 'itemOther', value: 'other' }, { key: 'itemTitle', value: 'localizedname' }],
                dataFilter: function (data) {
                    return data.content;
                }
                ,loadDefaultValue:true
                ,itemTmpl: '<li class="{{itemClass}}" value="{{itemValue}}" data-name="{{entityname}}">{{itemOther}}{{itemTitle}}</li>'
                , defaultSubmit: false
                , submithandler: function (obj,$target) {
                    obj.box.val( '/entity/list?entityname=' + $(this).attr('data-name'));
                    obj.ul.hide();
                    obj.vInput.val( '/entity/list?entityname=' + $(this).attr('data-name'));
                    obj.value = $(this).attr('value');
                    obj.wrap.attr('data-isactive', false);
                    obj.box.trigger('xmsAutoItem.click');
                }

            });

            loadTreeToolbar();
        });
        function loadTreeToolbar() {
            var $collapseOne = $('#collapseOne');
            $collapseOne.children('.xms-tree-toolbar').children('.xms-tree-toolbtn:first').on('click', function () {
                //$tree.find('.jqtree-folder').removeClass('jqtree-closed')
                $tree.tree('openAllNodes');
            });
            $collapseOne.children('.xms-tree-toolbar').children('.xms-tree-toolbtn:last').on('click', function () {
                // $tree.find('.jqtree-folder').addClass('jqtree-closed')
                $tree.tree('closeAllNodes');
            });
        }
        function doEditAction(id) {
            if (id == Xms.Utility.Guid.EmptyGuid.ToString()) {
                $.messager.popup(LOC_NOTSPECIFIED_RECORD);
                return;
            }
            getPrivilegeInfo(id);
            $editaction.prop("checked", true);
        }
        function doChildAction(id) {
            $form.resetForm();
            $form.find("input[name='parentprivilegeid']").val(id);
            $form.find("input[name='privilegeid']").val(Xms.Utility.Guid.EmptyGuid.ToString());
            $childaction.prop("checked", true);
        }
        function doCreateAction(id, node) {
            if (id == Xms.Utility.Guid.EmptyGuid.ToString()) {
                $.messager.popup(LOC_NOTSPECIFIED_RECORD);
                return;
            }
            $form.resetForm();
            $form.find("input[name='parentprivilegeid']").val(node.parent ? node.parent.id : Xms.Utility.Guid.EmptyGuid.ToString());
            $form.find("input[name='privilegeid']").val(Xms.Utility.Guid.EmptyGuid.ToString());
            $form.find("input[name='authorizationenabled'][value='True']").prop('checked', true);
            $form.find("input[name='isvisibled'][value='True']").prop('checked', true);
            $siblingaction.prop("checked", true);
        }
        function initTree() {
            $tree.tree({
                dragAndDrop: true
                , autoOpen: true
                , saveState: 'admin-menutree'
                , onCreateLi: function (node, $li) {
                    if (node.id != Xms.Utility.Guid.EmptyGuid.ToString()) {
                        $li.find('.jqtree-title').after('&nbsp;&nbsp;<a class="glyphicon glyphicon-trash" title="'+LOC_DELETE+'" href="javascript:removeNode(\'' + node.id + '\')" nodeid="' + node.id + '"></a>');
                    }
                },
                dataFilter: function (data) {
                    var res = Xms.Web.GetAjaxResult(data).content;
                    console.log(res);
                    return res
                }
                , onCanMoveTo: function (moved_node, target_node, position) {
                    //console.log(moved_node, target_node, position);
                    var moveid = moved_node.id;
                    var targetid = target_node.id;
                    var previd = moved_node.getPreviousNode() != null ? moved_node.getPreviousNode().id : 0;
                    var nextid = moved_node.getNextNode() != null ? moved_node.getNextNode().id : 0;
                    console.log(position + " moveparentid=" + moved_node.parent.id + ",targetid=" + target_node.id + ",targetparentid=" + target_node.parent.id);

                    var flag = false;
                    if (position == "inside" && moved_node.parent.id == target_node.id) {
                        flag = true;
                    }
                    else if (position == "after" && moved_node.parent.id == target_node.parent.id) {
                        flag = true;
                    }
                    return flag;
                }
                , selectable: true
            });

            $tree.bind(
                'tree.move',
                function (event) {
                    console.log('moved_node', event.move_info.moved_node);
                    console.log('target_node', event.move_info.target_node);
                    console.log('position', event.move_info.position);
                    console.log('previous_parent', event.move_info.previous_parent);
                    var moveid = event.move_info.moved_node.id;
                    var targetid = event.move_info.target_node.id;
                    var parentid = event.move_info.previous_parent.id;
                    var position = event.move_info.position;
                    $.get(ORG_SERVERURL + "/privilege/MovePrivilege?moveid=" + moveid + "&targetid=" + targetid + "&parentid=" + parentid + "&position=" + position, function (response) {
                        console.log(response);
                        $tree.tree('reload');
                    });
                }
            );
            $tree.bind(
            'tree.select',
            function (event) {
                if (event.node) {
                    // node was selected
                    var node = event.node;
                    $tree.tree('openNode', node);
                    $form.find("input[name='actionstatus']").prop("checked", false);
                    if (node.id == Xms.Utility.Guid.EmptyGuid.ToString()) {
                        doChildAction(Xms.Utility.Guid.EmptyGuid.ToString());
                        return;
                    }
                    doEditAction(node.id);
                }
            }
            );
        }
        function getPrivilegeInfo(id) {
            Xms.Web.GetJson("/privilege/EditPrivilege?id=" + id, null, function (data) {
                console.log(data);
                if (!data) return;
                var entity = data.content;
                console.log(entity);
                $form.resetForm();
                $editaction.prop("checked", true);
                //$form.find("input[name='parentprivilegeid']").val(entity.parentprivilegeid);
                for (var p in entity) {
                    if (typeof (entity[p]) != "function") {
                        var value = entity[p] == null ? "" : entity[p];
                        var target = $form.find("input[name='" + p.toLowerCase() + "']");
                        if (target.is(":radio") || target.is(":checkbox")) {
                            target.each(function (i, n) {
                                if ($(n).val().toLowerCase() == value.toString().toLowerCase()) {
                                    $(n).prop("checked", true);
                                }
                            });
                        }
                        else {
                            target.val(entity[p]);
                            if (p == "url") {
                                target.siblings('.xms-mutilauto-wrap').children('input').val(entity[p])
                            }
                        }
                    }
                }
            });
        }
        function removeNode(id) {
            var node = $tree.tree('getNodeById', id);
            Xms.Web.Del(id, "/privilege/deleteprivilege", false, function (response) {
                if (response.IsSuccess) {
                    $tree.tree('removeNode', node);
                    $form.resetForm();
                }
            });
        }
        function loadTree() {
            $tree.tree('reload');
        }
        function bindSelectedAction(result) {
            $('#SystemName').val('admin');
            $('#ClassName').val(result[0].classname.replace('Controller', ''));
            $('#MethodName').val(result[0].methodname);
            $('#DisplayName').val(result[0].displayname);
            $('#Url').val(result[0].classname.replace('Controller', '') + '/' + result[0].methodname);
        }
    </script>
}